package com.john.bms.config;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author:张家小帅哥
 * @Date:2020/9/21 11:10
 * @Version:1.0
 * @Description:
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Object handleException(Exception e) {
        e.printStackTrace();
        String msg = e.getMessage();
        if (msg == null || msg.equals("")) {
            msg = "服务器出错";
        }
        Map<String,Object> map = new HashMap<>(5);
        map.put("error", true);
        map.put("code", 50014);
        map.put("message", msg);
        return map;
    }

}
